#ifndef SAVEVIDEO_H
#define SAVEVIDEO_H


#include <codec.h>
#include <ogg/ogg.h>
#include <theoraenc.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <time.h>
#include <vorbis/vorbisenc.h>


#define YPOS 0
#define UPOS 1
#define VPOS 2

struct savevideodata {
    FILE *ogg_fp_va;
    ogg_stream_state ogg_os_video, ogg_os_audio;
    ogg_packet opo, opv;   
    ogg_page ogo, ogv;

    int chroma_format;
    long framerate;
    th_comment tc;

    th_ycbcr_buffer ycbcr;

    th_info ti;
    th_enc_ctx *td;

    unsigned long yuv_w;
    unsigned long yuv_h;

    int xdims, ydims;

    vorbis_info      vi; 
    vorbis_comment   vc; 

    vorbis_dsp_state vd; 
    vorbis_block     vb;

    long samplerate;
    long sample;
    long frame;
    long samplesperframe;

    long granulepause;
    sem_t videogo, audiogo, warmupgo;

};
 

struct savevideodata * setupogg(char * filename);
void setuptheora(struct savevideodata *svd, int x, int y, int framerate, int *ydatasize, int *udatasize, int *vdatasize);
void saveoggframe(struct savevideodata *svd, int last);
void closeogg(struct savevideodata *svd);
void setupvorbis(struct savevideodata *svd, long sr);
void saveoggvorbis(struct savevideodata *svd);
void closevorbis(struct savevideodata *svd);
void closetheora(struct savevideodata *svd);

#endif
